
// INCLUDES ********************************************************************

#include "Configuration.h"

#include "Logger.h"

#include <sstream>



const char* ConfigurationKeys[] =
{
    "System version",
    "Retina support",
    "DisplayLink support",
    "NPOT support",
    "Screensize"
};

// NAMESPACES ******************************************************************

using namespace Meteor;

// *****************************************************************************

#pragma mark -
#pragma mark Constructor
// -----------------------------------------------------------------------------

Configuration::Configuration()
{
    GetSystemInformation();
}

#pragma mark -
#pragma mark Singleton Destructor
// -----------------------------------------------------------------------------

Configuration::~Configuration()
{
    containerType::iterator entry = mEntries.begin();
    
    while ( entry != mEntries.end())
    {
        delete ( *entry).second;
    }

    mEntries.clear();
}


#pragma mark -
#pragma mark Removal
// -----------------------------------------------------------------------------

void Configuration::RemoveValueForyKey( const std::string& key)
{
    containerType::iterator entry = mEntries.find( key);
    
    if ( entry == mEntries.end())
    {
        Logger::DebugLog( "Configuration::RemoveValueForyKey - unknown key.");
    }
    
    delete ( *entry).second;
    
    mEntries.erase( entry);
}


#pragma mark -
#pragma mark System information
// -----------------------------------------------------------------------------

void Configuration::GetSystemInformation()
{
    NSString* systemVersion = [[UIDevice currentDevice] systemVersion];
    
    std::stringstream version;
    
    version << [systemVersion floatValue];
    
    SetValueForKey<std::string>( "System version", version.str());
    
    if ( [[UIScreen mainScreen] scale] == 2.0f)
    {
        SetValueForKey<bool>( "Retina support", true);
    }
    else
    {
        SetValueForKey<bool>( "Retina support", false);
    }
    
    if ( [systemVersion floatValue] > 3.1f)
    {
        SetValueForKey<bool>( "DisplayLink support", true);
    }
    else
    {
        SetValueForKey<bool>( "DisplayLink support", false);
    }
}
